package com.kolon.business.app.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.kolon.business.app.dao.AppDao;
import com.kolon.framework.interfaces.SimpleController;
import com.kolon.framework.util.ComUtil;
import com.kolon.framework.util.MsgUtil;

/**
 * 서비스 앱 최신버전 다운로드 URL을 보내주는 클래스
 * @author stone
 */
@Controller("com.kolon.business.app.controller.ServAppUrlController")
public class ServAppUrlController implements SimpleController {

	@Resource(name="AppDaoImpl")
	private AppDao appDao;
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@RequestMapping(value="/business/app/servAppUrl.do")
	public ModelAndView controller(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		ModelAndView modelAndView = new ModelAndView();
		// 파라미터
		String appNm = request.getParameter("appNm");
		String domain =  MsgUtil.getMessage("domain.iis.url");
		// 파라미터 MAP
		Map map = new HashMap();
		map.put("appNm", appNm);
		map.put("frfTp", ComUtil.getMobileOS(request.getHeader("user-agent")));
		// 서비스 조회
		Map servInfo = appDao.getServMap(map);
		if (servInfo != null) {
			if ("iPhone".equals(servInfo.get("FRF_TP"))) {
				modelAndView.addObject("servAppUrl", MsgUtil.getMessage("app.iPhone.url")+
						domain+MsgUtil.getMessage("app.file.iPhone.path")+servInfo.get("FDR_NM")+"/"+servInfo.get("FILE_S_NM_1"));
			} else if ("Android".equals(servInfo.get("FRF_TP"))) {
				modelAndView.addObject("servAppUrl", domain+MsgUtil.getMessage("app.file.Android.path")+
						servInfo.get("FDR_NM")+"/"+servInfo.get("FILE_S_NM_1"));
			} else {
				modelAndView.addObject("servAppUrl", "NOT");
			}
		} else {
			modelAndView.addObject("servAppUrl", "NOT");
		}
		return modelAndView;
		
	}

}
